﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using JwtDemoWebApi.Models;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;

namespace JwtDemoWebApi.Controllers
{
    [ApiController]
    [Route("[controller]/[action]")]
    //[Authorize]
    public class BaseController : ControllerBase, IActionFilter
    {
        protected IEnumerable<Claim> claims { get; set; }

        public void OnActionExecuted(ActionExecutedContext context)
        {

        }

        public void OnActionExecuting(ActionExecutingContext context)
        {
            //claims = context.HttpContext.AuthenticateAsync().Result.Principal.Claims;//这种方式必须在控制器上方拥有[Authorize]特性时才可用
            claims = context.HttpContext.User.Claims;
        }
    }
}
